/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelExigencia.java
 *
 * Created on 19-may-2010, 18:03:53
 */

package edu.ieslaferreria.creditsintesis.builders.Swing;

import edu.ieslaferreria.creditsintesis.rmi.EventChangePanel;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;

/**
 *
 * @author Administrador
 */
public class JPanelExigencia extends JPanelGame {
  
    /** Creates new form JPanelExigencia */
    public JPanelExigencia() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxExigencies = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButtonVolver = new javax.swing.JButton();

        jComboBoxExigencies.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBoxExigencies.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxExigenciesActionPerformed(evt);
            }
        });

        jLabel1.setText("Exigencias Posibles");

        jList1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        jButtonVolver.setText("Volver");
        jButtonVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVolverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jComboBoxExigencies, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18))
                    .addComponent(jButtonVolver, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(40, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBoxExigencies, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE)
                        .addComponent(jButtonVolver)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxExigenciesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxExigenciesActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_jComboBoxExigenciesActionPerformed

    private void jButtonVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVolverActionPerformed
try {
/*meto cliente en un arraylist...los eventos tienen arraylist, quizas seria bastante un string*/
            ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());


             /*envio el canvio a mi mismo con boolean de respuesta a false*/
            getClient().onMessage(new EventChangePanel(null,A_PANELINICI,false,alias,getPontPanel()));

   /*envio por el puente de la partida a todos los players de susodicha menos yo,
   * enviando mi nombre para que sepan a quien NO debe enviarselo*/
            this.getPontPanel().send(new EventChangePanel(null,A_PANELMENUWAIT,false,alias,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }



try {
/*meto cliente en un arraylist...los eventos tienen arraylist, quizas seria bastante un string*/
            ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());


             /*envio el canvio a mi mismo con boolean de respuesta a false*/
            getClient().onMessage(new EventChangePanel(null,A_PANELINICI,false,alias,getPontPanel()));

   /*envio por el puente de la partida a todos los players de susodicha menos yo,
   * enviando mi nombre para que sepan a quien NO debe enviarselo*/
            this.getPontPanel().send(new EventChangePanel(null,A_PANELINICI,false,alias,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButtonVolverActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonVolver;
    private javax.swing.JComboBox jComboBoxExigencies;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
   

    public void update(Map<String, List<String>> opcions,ArrayList<String> extras) {
       this.jComboBoxExigencies.setModel(new DefaultComboBoxModel(opcions.get(OPCIO_BASICA).toArray()));

       DefaultListModel M = new DefaultListModel();

       int cont = 0;
       while(cont<extras.size()){

           M.add(cont,extras.get(cont));

           cont++;
       }

       this.jList1.setModel(M);
            
    }

}
